/*
 * 文件名：RequestCache.java
 * 版权：MoonBox 
 * 修改人：Peter
 * 修改时间：2018年9月30日
 * 修改内容：新增
 */
package com.renzhebiao.lkang.request;

/**
 * <p>
 * 
 * @author Peter
 * @since 1.0.0
 */
public class RequestCache {

    private static ThreadLocal<RequestPayload> request = new ThreadLocal<RequestPayload>() {

        @Override
        protected RequestPayload initialValue() {
            return new RequestPayload();
        }
    };

    public static void set(RequestPayload v) {
        request.set(v);
    }

    /**
     * 清除缓存
     */
    public static void clean() {
        if (request == null || request.get() == null) {
            return;
        }
        request.set(null);
    }

    /**
     * 获取请求
     * 
     * @return
     */
    public static RequestPayload get() {
        return request.get();
    }

    /**
     * 获取用户信息
     * 
     * @return
     */
    public static Long userId() {
        RequestPayload req = get();
        if (req != null) {
            return req.getUserId();
        }
        return null;
    }

}
